<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>

	<head>
		<title>物资管理系统</title>
		<meta charset="utf-8">
		<link rel="icon" href="<%=basePath %>images/favicon.png" type="image/x-icon" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>css/login.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrap.css">
	</head>

	<body>
		<div id="shade"></div>
		<div class="login">
			<div class="lg100">
				<nav>
					<div class="lg_logo"></div>
				</nav>

			</div>
			<%-- <img class="lg_race" src="<%=basePath %>ysq/images/login_circle.png"/> --%>
			<form class="lg_message" id="userlogin" action="javascript:;">
				<div class="user">用户登录</div>
				<div class="login_num"><i><em></em><span id="passid"></span><input id="acc" type="text" value="${meterial_manage_username }" autocomplete="off"/></i>
					<div id="accErr" class="errInfo hide">test</div>
				</div>
				<div class="login_psw"><i><em></em><span id="password"></span><input id="pwd" type="password" value="" autocomplete="off"/></i>
					<div id="pwdErr" class="errInfo hide">test</div>
				</div>
				<p id="accPwd_error" style="display: none;color: #B64031;font-weight: bold;"></p><br/>
				<div><input id="login" type="button" value="登录" />
					<input class="reset" type="reset" value="重置" />
					</div>
			</form>
			<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
		</div>
		<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
		<script src="<%=basePath %>js/jquery.cookie.js"></script>
		<script src="<%=basePath %>js/bootstrap.js"></script>
		<script src="<%=basePath %>js/public.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("#acc").val($.cookie("meterial_manage_username"));
				$("#pwd").val("");

				$("#login").click(function() {
					var username = $("#acc").val();
					var userpass = $("#pwd").val();
					username = $.trim(username);
					userpass = $.trim(userpass);
					$("#loginTips").css({
						display: "none"
					});

					if(username.length < 1) {
						Prompt.alert("提示", "请输入正确的用户名!");
						return false;
					}
					if(userpass == '') {
						Prompt.alert("提示", "请输入正确的密码!");
						return false;
					}
					var date = new Date();
					date.setTime(date.getTime() + 365 * 24 * 60 * 60 * 1000);
					document.cookie="meterial_manage_username="+username+"; expires="+date.toGMTString();
					$.ajax({
						url: "<%=basePath %>user/toLogin.do",
						type: "post",
						dataType: "json",
						data: {
							username: username,
							password: userpass
						},
						success: function(data) {
							var result = data.success;
							var error = data.errorInfo;
							if(result) {
								location.href = location.href;
							} else {
								Prompt.alert("提示", error);
							}
						}
					})
				})
			})

			$(function() {
				document.onkeydown = function(e) {
					var ev = document.all ? window.event : e;
					if(ev.keyCode == 13) {
						$("#login").click();
					}
				}
			});

			//账号密码输入提示显示/隐藏
			$("body").on("focus", "input", function() {
				$(this).parent().children("span").hide();
				$("#userlogin div.errInfo").addClass("hide");
				$("#accPwd_error").css("display", "none");
			})
			$("body").on("blur", "input", function() {
				if($(this).val() == "" || $(this).val() == null) {
					$(this).parent().children("span").show();
				}
			})
		</script>

	</body>

</html>